//
//  DataViewController.m
//  逗她盒子
//
//  Created by Qiaofeng on 15/6/9.
//  Copyright (c) 2015年 Qiaofeng. All rights reserved.
//

#import "DataViewController.h"
#import "DataTableViewCell.h"
#import "SearchViewController.h"
@interface DataViewController ()<UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate>
@property (nonatomic, retain)NSMutableArray *dataArray;
@end

@implementation DataViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self =  [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.dataArray = [[NSMutableArray alloc]init];
        NSMutableDictionary *adic= [NSMutableDictionary dictionary];
        NSMutableDictionary *bdic= [NSMutableDictionary dictionary];
        NSMutableDictionary *cdic= [NSMutableDictionary dictionary];
        NSMutableDictionary *ddic= [NSMutableDictionary dictionary];
        [adic setValue:@"英雄" forKey:@"a"];
        [adic setValue:@"iconfont-shoucang.png" forKey:@"b"];
        [bdic setValue:@"物品" forKey:@"a"];
        [bdic setValue:@"iconfont-qingchu.png" forKey:@"b"];
        [cdic setValue:@"天梯" forKey:@"a"];
        [cdic setValue:@"iconfont-yejianzhuanhuan.png" forKey:@"b"];
        [ddic setValue:@"知名玩家" forKey:@"a"];
        [ddic setValue:@"iconfont-yonghu.png" forKey:@"b"];
        [self.dataArray addObject:adic];
        [self.dataArray addObject:bdic];
        [self.dataArray addObject:cdic];
        [self.dataArray addObject:ddic];
    }
    return self;
}


// 创建tableView
- (void)createTable
{

    self.table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    UIColor *gray = [UIColor colorWithRed:240/255 green:240/255 blue:240/255 alpha:0.1];
    [self.table setBackgroundColor:gray];
    self.table.delegate = self;
    self.table.dataSource = self;
    self.table.rowHeight = 70;
    [self.view addSubview:self.table];


    self.table.tableFooterView = [[UIView alloc]init];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.dataArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *cellIdentfy = @"cell";
    DataTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentfy];
    if (!cell) {
        cell = [[DataTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentfy];
    }
    return cell;
    
}



- (void)loadView
{
    [super loadView];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self searchbar];
    [self createTable];
   
}
- (void)searchbar
{

    UISearchBar *searchBar= [[UISearchBar alloc]init];     // 创建SearchBar
    searchBar.placeholder = @"搜索昵称,ID,英雄,物品...";    // 占位符
    self.navigationItem.titleView = searchBar; // 在title上添加searchbar
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor]; //设置bar上图片的颜色
    searchBar.delegate = self;     // 代理人
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;     // 设置状态栏为白字
  
}



// 点击Search的转跳
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    // push进去隐藏bar
    self.hidesBottomBarWhenPushed = YES;
    
    SearchViewController *search = [[SearchViewController alloc]init];
    [self.navigationController pushViewController:search animated:YES];
    
    return YES;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
